package com.company.class12;

/**
 * @Classname Sum
 * @Description 类型说明
 * @Date 2022/5/8 20:05
 * @Created by zbw
 */

public class OperationNum {
    private static String ADD = "+";
    private static String SUB = "-";
    private static String RIDE = "*";
    private static String REMOVE = "/";

    public String resultMSG;

    public int FourArithmetic(String a,String b,String operation){
        int sum = 0;
        int x=0,y=0;
        resultMSG = "";
        if(a!=null && b!=null && operation != null){
            try {
                x = Integer.parseInt(a);
                y = Integer.parseInt(b);
            }catch (Exception e){
                resultMSG = "a和b需要输入数字！";
                System.out.println(e.getMessage());
            }
            if(resultMSG.equals("a和b需要输入数字！")) {
                System.out.println("a和b需要输入数字！");
            }else {
                if (operation.equals(ADD)) {
                    sum = x + y;
                    resultMSG = "加法运算，测试成功";
                    System.out.println("加法运算，测试成功");
                } else if (operation.equals(SUB)) {
                    sum = x - y;
                    resultMSG = "减法运算，测试成功";
                    System.out.println("减法运算，测试成功");
                } else if (operation.equals(RIDE)) {
                    sum = x * y;
                    resultMSG = "乘法运算，测试成功";
                    System.out.println("乘法运算，测试成功");
                } else if (operation.equals(REMOVE)) {
                    sum = x / y;
                    resultMSG = "除法运算，测试成功";
                    System.out.println("除法运算，测试成功");
                } else {
                    resultMSG = "运算必须为+、-、*、/";
                    System.out.println("运算必须为+、-、*、/");
                }
            }

        }else{
            resultMSG = "输入的三个参数中存在有空参数！";
            System.out.println("输入的三个参数中存在有空参数！");
        }
        return sum;
    }

    public static void main(String[] args) {
        OperationNum opt = new OperationNum();
        System.out.println(opt.FourArithmetic("9", "3", "+"));

    }


    public String getResultMSG() {
        return resultMSG;
    }

}
